import  {CHANGE_INPUT_VALUE}  from "./actionType"
const defaultState = {
    inputValue: 'Write Something',
    list: [
        '已首都机场南京财经',
        '及飒飒超级好吃计算机'
    ]
} // 默认数据

// state指的是原始仓库里面的状态，action指的是store推送过来新的状态
export default (state = defaultState, action) => {


    if (action.type === CHANGE_INPUT_VALUE) {
        // state.inputValue = action.value  // reducer里面不能修改state
        let newState =JSON.parse(JSON.stringify(state))
        newState.inputValue = action.value
        return newState
    }

    if(action.type === 'add_item') {
        let newState =JSON.parse(JSON.stringify(state))
        newState.list.push(newState.inputValue)
        newState.inputValue = ''
        return newState
    }

    if(action.type === 'delete_item') {
        let newState =JSON.parse(JSON.stringify(state))
        newState.list.splice(action.value, 1)
        return newState
    }

    return state
}